<template>
  <van-popup
    class="assist-selection-popup task-selection-popup"
    v-bind="$attrs"
    position="bottom"
    v-on="$listeners"
    get-container="body"
  >
    <div class="van-picker__toolbar van-hairline--bottom">
      <button
        type="button"
        class="van-picker__cancel"
        @click="handleCancel"
      >
        取消
      </button>
      <div class="van-ellipsis van-picker__title">
        选择协助人员
      </div>
      <button
        type="button"
        class="van-picker__confirm"
        @click="handleConfirm"
      >
        确认
      </button>
    </div>
    <div class="pick-list">
      <van-cell-group>
        <van-cell
          :class="{
            'select-cell': result.Account === item.Account,
          }"
          v-for="item in list"
          clickable
          :key="item.Account"
          :title="item.DisplayName"
          @click="toggle(item)"
        >
          <template #right-icon>
            <div class="right-area">
              {{ item.ISKX ? "空闲" : "忙碌" }}
            </div>
          </template>
        </van-cell>
      </van-cell-group>
    </div>
  </van-popup>
</template>

<script>
import { Pad_Repair_GetStartOperation } from "../../api/index";
export default {
  name: "AssistSelectionPopup",
  inheritAttrs: false,
  props: {
    activeData: {
      type: Object,
      default: () => {
        return {};
      },
    },
  },
  watch: {
    activeData: {
      handler(val, oldVal) {
        if (val.Id !== oldVal.Id) {
          this.getData();
        }
      },
      deep: true,
    },
  },
  data() {
    return {
      keywords: "",
      list: [
        // {
        //   MaintainAccount: "zhuqing",
        //   MaintainName: "朱青",
        //   ISKX: 0,
        //   BeBusys: [
        //     {
        //       MaintainWorkType: "箱体部",
        //       MaintainWorkName: "加工中心",
        //       EquipmentLine: "",
        //       FaultType: ["机械传动故障"],
        //     },
        //   ],
        // },
      ],
      result: {},
    };
  },
  methods: {
    getData() {
      this.result = "";
      Pad_Repair_GetStartOperation()
        .then((res) => {
          if (res.ReturnResult === "1") {
            this.list = res.ReturnData;
          } else {
            this.$notify(res.Message);
          }
        })
        .catch((err) => {
          this.$notify(err);
        });
    },
    handleCancel() {
      this.$emit("input", false);
    },
    handleConfirm() {
      this.$emit("confirm", this.result);
    },
    toggle(item) {
      this.result = item;
    }
  },
};
</script>
